﻿using System;
using System.Web;
using System.Web.Routing;
using complex.Registries;
using FubuMVC.Core;
using FubuMVC.StructureMap;
using StructureMap;
using StructureMap.Graph;

namespace complex
{
    public class Global
        : HttpApplication
    {
        protected void Application_Start(object sender, EventArgs e)
        {
            FubuApplication
                .For<ComplexRegistry>()
                .StructureMapObjectFactory(s => s.Scan(ForRegistriesAndDefaults))
                .Bootstrap(RouteTable.Routes);
        }

        private static void ForRegistriesAndDefaults(IAssemblyScanner scan)
        {
            scan.TheCallingAssembly();
            scan.LookForRegistries();
            scan.WithDefaultConventions();
        }

        protected void Application_End(object sender, EventArgs e)
        {
            ObjectFactory.Container.Dispose();
        }
    }
}